package com.um.jdy.platform.platform.manager;

import cn.hutool.core.bean.BeanUtil;
import com.um.jdy.common.platform.entity.dto.RentSettingDTO;
import com.um.jdy.common.platform.entity.po.RentSetting;
import com.um.jdy.common.platform.entity.vo.RentSettingVO;
import com.um.jdy.common.platform.service.RentSettingService;
import com.um.springboot.starter.orm.entity.Response;
import com.um.springboot.starter.orm.manager.BaseManager;
import com.um.springboot.starter.utils.UMBeanUtils;
import org.springframework.stereotype.Component;

/**
 * 管理类：应用信息设置
 */
@Component
public class RentSettingManager extends BaseManager<RentSettingService> {

    /**
     * 详情
     *
     * @return
     */
    public Response<RentSettingVO> get() {
        RentSetting rentSetting = service.getEntity("com_id", getComId());
        if(rentSetting == null){
            rentSetting = new RentSetting();
            rentSetting.setComId(getComId());
            rentSetting.setDistance(1000);
            rentSetting.setMaxOrders(2);
            rentSetting.setShopDisplayType("distance");
            service.save(rentSetting);
        }
        return Response.success(UMBeanUtils.copyBean(rentSetting,RentSettingVO.class));
    }

    /**
     * 更新
     *
     * @param id
     * @param rentSettingDTO
     * @return
     */
    public Response update(String id, RentSettingDTO rentSettingDTO) {
        RentSetting rentSetting = BeanUtil.copyProperties(rentSettingDTO, RentSetting.class);
        rentSetting.setPlatformRentSettingId(id);
        service.updateEntity(rentSetting);
        return Response.success();
    }

}
